package com.cn.webservices;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;  
import org.apache.cxf.bus.spring.SpringBus;  
import org.apache.cxf.jaxws.EndpointImpl;  
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;  
import org.springframework.context.annotation.Configuration;  
import org.springframework.core.Ordered;

@Configuration
public class CxfConfig {
	    @Bean(name = Bus.DEFAULT_BUS_ID)
	    public SpringBus springBus() {
	        return new SpringBus();
	    }
	    
	    @Bean  
	    public ServletRegistrationBean servletRegistrationBean() {  
	        ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/services/*");  
//	        bean.setLoadOnStartup(0);  
//	        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);  
	        return bean;  
	    }  
	    @Bean  
	    public TestServiceImpl testServiceImpl() {  
	        return new TestServiceImpl();  
	    }  
	  
	    @Bean  
	    public Endpoint endpoint() {  
	        EndpointImpl endpoint = new EndpointImpl(springBus(), testServiceImpl());  
	        endpoint.publish("/test");  
	        endpoint.getInInterceptors().add(new AuthInterceptor());  
	        return endpoint;  
	    }  
}
